package com.fbty.mt.action.admin;

import java.util.Date;
import java.util.Map;

import com.fbty.base.action.BaseAction;
import com.fbty.mt.domain.CheckInfo;
import com.fbty.mt.domain.OnlyIpInfo;
import com.fbty.mt.service.IpService;
import com.fbty.mt.service.ProxyService;
import com.fbty.mt.utils.IPInfoHelper;
import com.fbty.mt.utils.StaticValue;

public class OnlyIpAction extends BaseAction {

	private String exportIp;

	private int exportPort;

	private String type;

	private String proxyType;

	private double price;

	private IpService ipInfoService;

	private ProxyService proxyService;

	public void setProxyService(ProxyService proxyService) {
		this.proxyService = proxyService;
	}

	public void setIpInfoService(IpService ipInfoService) {
		this.ipInfoService = ipInfoService;
	}

	public String execute() {
		OnlyIpInfo info = new OnlyIpInfo();
		info.setExportIp(exportIp);
		info.setExportPort(exportPort);
		info.setState(0);
		info.setPrice(price);
		info.setType(type.toUpperCase());
		info.setProxyType(proxyType);
		info.setSpeed("0.11");
		Map<String, String> map = IPInfoHelper.getIPInfo(info.getExportIp());
		info.setCity(map.get("City") == null ? "--" : map.get("City"));
		info.setCountry(map.get("Country") == null ? "--" : map.get("Country"));
		info.setRegion(map.get("Region") == null ? "--" : map.get("Region"));
		info.setUploadTime(new Date());
		ipInfoService.saveOnlyIpInfo(info);
		return "success";
	}

	public void setExportIp(String exportIp) {
		this.exportIp = exportIp;
	}

	public void setType(String type) {
		this.type = type;
	}

	public void setProxyType(String proxyType) {
		this.proxyType = proxyType;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public void setExportPort(int exportPort) {
		this.exportPort = exportPort;
	}

}
